/**
 * 快速分摊
 */

import React, { Component } from 'react'
import { base, createPage, toast } from 'nc-lightapp-front'
import initTemplate, { onChangeRule } from './initTemplate'
import presetVar from './presetVar'
import "./index.less"
const { NCButton, NCModal } = base

class QuickShare extends Component {
    
    constructor(props) {
        super(props)
        props.use.form(presetVar.headCode)
        props.use.table(presetVar.bodyCode)
        initTemplate.call(this)
    }
    
    componentDidMount() {
        
    }
    
    onSureClick() {
        const { onHide, onQuickShareClick } = this.props
        if(this.selectRulePk) {
            onQuickShareClick && onQuickShareClick(this.selectRulePk)
            onHide()
        }else {
            let multiLang = this.props.MutiInit.getIntl(2011);
            toast({ content: multiLang && multiLang.get('2207KSFT-0001') , color: 'warning' });
        }
    }

    onCancelClick() {
        const { onHide } = this.props
        onHide()
    }

    render() {
        let multiLang = this.props.MutiInit.getIntl(2011);
        const { createForm } = this.props.form;
        const { createSimpleTable } = this.props.table;
        const { size, show, onHide, title, getQuickShareAmount } = this.props;
        const value = getQuickShareAmount()
        this.props.form.setFormItemsValue(presetVar.headCode, { shareAmount:value })
        this.props.table.setAllTableData(presetVar.bodyCode, {rows:[]})
        this.selectRulePk = null
        return (
            <NCModal size={ size } show={ show } keyboard={ false } onHide={ onHide }>
                <NCModal.Header closeButton="true">                                                                    
                    <NCModal.Title >{ title }</NCModal.Title>
                </NCModal.Header>
                <NCModal.Body>
                    <div className="nc-bill-card">
                        <div className="nc-bill-top-area">
                            <div className="nc-bill-form-area">
                                {createForm(presetVar.headCode, {})}
                            </div>
                        </div>
                        <div className="nc-bill-bottom-area">
                            <div className="nc-bill-table-area">
                                {createSimpleTable(presetVar.bodyCode, {
                                    adaptionHeight: true
                                })}
                            </div>
                        </div>
                    </div>
                </NCModal.Body>
                <NCModal.Footer>
                    <NCButton colors="primary" onClick={this.onSureClick.bind(this)}>{ multiLang && multiLang.get('2011-0003') }</NCButton>
                    <NCButton onClick={this.onCancelClick.bind(this)} >{ multiLang && multiLang.get('2011-0002') }</NCButton>
                </NCModal.Footer>
            </NCModal>
        )
    }
}

export default createPage({mutiLangCode: '2011'})(QuickShare)